<template>
  <div class="recommend-video-box" @click="gotoTvInfo(data.video_id)" >
    <TipsView :icon="Tipsicon" :text="Tipstext" ref="childTips"></TipsView>
              <div class="recommend-video">
                <div class="video-pic" >
                  <img :src="data.video_cover.video_cover_url" :style="coverSize" alt="" />
                  <div class="duration">{{duration}}</div>
                </div>
                <div class="video-info">
                  <div class="video-infotitle">{{data.video_title}}</div>
                  <div class="publish-author-name" @click.stop="goUserHome(data.uid)">@{{data.username}}</div>
                  <div class="publish-info">
                    <span class="views">{{data.video_play_num}}次观看 </span> •
                    <span class="publish-days">{{data.video_time}}</span>
                  </div>
                </div>
              </div>
            </div>
</template>

<script>
import TipsView from '@/components/utilView/tipView.vue'
import http from '@/util/http'
import { mapState } from 'vuex'
export default {
  data () {
    return {
      Tipsicon: 'icon-jinggao',
      Tipstext: ''
    }
  },
  components: {
    TipsView
  },
  props: {
    data: {
      type: Object,
      default: null
    }
  },
  computed: {
    ...mapState(['user']),

    // 显示视频封面的中心部分
    coverSize () {
      const a = {}
      if (this.data.video_cover.width >= this.data.video_cover.height) {
        a.width = this.data.video_cover.width / this.data.video_cover.height * 100 + '%'
        a.left = -(this.data.video_cover.width / this.data.video_cover.height - 1) / 2 * 100 + '%'
        a.height = '100%'
      } else {
        a.height = this.data.video_cover.height / this.data.video_cover.width * 100 + '%'
        a.top = -(this.data.video_cover.height / this.data.video_cover.width - 1) / 2 * 100 + '%'
        a.width = '100%'
      }
      return a
    },
    // 显示视频的时长
    duration () {
      let time = ''
      if (this.data.video_duration < 60) {
        let miao = this.data.video_duration
        if (this.data.video_duration < 10) {
          miao = '0' + this.data.video_duration
        }

        time = '0:' + miao
      } else if (this.data.video_duration > 60 && this.data.video_duration < 3600) {
        let fen = null
        let miao = null
        fen = Math.trunc(this.data.video_duration / 60)
        miao = Math.trunc(this.data.video_duration % 60)
        if (miao < 10) {
          miao = '0' + miao
        }
        if (fen < 10) {
          fen = '0' + fen
        }
        time = fen + ':' + miao
      } else if (this.data.video_duration > 3600) {
        let shi = null
        let fen = null
        let miao = null
        shi = Math.trunc(this.data.video_duration / 3600)
        fen = Math.trunc((this.data.video_duration % 36000) / 60)
        miao = Math.trunc(this.data.video_duration % 60)
        if (miao < 10) {
          miao = '0' + miao
        }
        if (fen < 10) {
          fen = '0' + fen
        }
        time = shi + ':' + fen + ':' + miao
      }

      return time
    }
  },
  methods: {
    tipsMethod (text) {
      this.$refs.childTips.HanderTiming(1200)
      this.Tipstext = text
    },
    // 跳转到查看其他用户详情
    goUserHome (uuid) {
      // 校验登录
      const checkState = this.$checkU()
      if (!checkState) {
        this.tipsMethod('请先登录')
        return
      }
      if (this.user.uid === uuid) {
        this.$router.push({ path: '/user/myhome' })
      } else {
        this.$router.push({ path: '/home/userHome', query: { uuid: uuid } })
      }
    },
    // 跳转到视频详情页面
    gotoTvInfo (vid) {
      this.$router.push({ path: '/videodetail', query: { videoId: vid } })
      // 记录播放历史
      // 传递观看者的id和视频的id
      http.addTvhistory(this.user.uid, vid).then(res => {
        console.log(res.data)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.recommend-video-box {
            width: 100%;
            margin: 15px 0;

            .recommend-video {
              width: 100%;
              display: flex;
              justify-content: space-between;
              align-items: center;
              margin: 10px 0;
              cursor: pointer;

              .video-pic {
                width: 200px;
                height: 100px;
                background: #000;
                overflow: hidden;
                border-radius: 5px;
                cursor: pointer;
                position: relative;

                img {
                    position: absolute;

                  border-radius: 5px 5px 0 0;
                  transition: all 0.3s;
                  object-fit: cover;

                  &:hover {
                    filter: brightness(90%);
                    transform: scale(1.1);
                    opacity: 1;
                  }
                }
                .duration {
                  color: #eee;
                  font-size: 12px;
                  padding: 0 5px;
                  background: rgba($color: #000, $alpha: 0.8);
                  position: absolute;
                  bottom: 5%;
                  right: 5%;
                }
              }
              .video-info {
                width: 200px;
                margin-left: 10px;
                color: #333;
                font-size: 16px;
                display: inline-block;
                .video-infotitle {
                  padding-bottom: 10px;
                  &:hover {
                    color: #f90;
                  }
                }
                .publish-author-name {
                  color: #939393;
                  font-size: 14px;
                  padding-bottom: 10px;
                  &:hover {
                    color: #f90;
                  }
                }
                .publish-info {
                  color: #939393;
                  font-size: 14px;
                }
              }
            }
          }
@media screen and (min-width: 1024px)  and (max-width: 1280px) {
    .recommend-video-box {
            width: 100%;
            margin: 15px 0;

            .recommend-video {
              width: 100%;
              display: flex;
              justify-content: space-between;
              align-items: center;
              margin: 10px 0;
              cursor: pointer;

              .video-pic {
                width: 200px;
                height: 100px;
                background: #000;
                overflow: hidden;
                border-radius: 5px;
                cursor: pointer;
                position: relative;

                img {
                    position: absolute;

                  border-radius: 5px 5px 0 0;
                  transition: all 0.3s;
                  object-fit: cover;

                  &:hover {
                    filter: brightness(90%);
                    transform: scale(1.1);
                    opacity: 1;
                  }
                }
                .duration {
                  color: #eee;
                  font-size: 12px;
                  padding: 0 5px;
                  background: rgba($color: #000, $alpha: 0.8);
                  position: absolute;
                  bottom: 5%;
                  right: 5%;
                }
              }
              .video-info {
                width: 180px;
                margin-left: 10px;
                color: #333;
                font-size: 14px;
                display: inline-block;
                .video-infotitle {
                  padding-bottom: 6px;
                  &:hover {
                    color: #f90;
                  }
                }
                .publish-author-name {
                  color: #939393;
                  font-size: 13px;
                  padding-bottom: 6px;
                  &:hover {
                    color: #f90;
                  }
                }
                .publish-info {
                  color: #939393;
                  font-size: 13px;
                }
              }
            }
          }
    }

    @media screen and (min-width: 768px)  and (max-width: 1024px) {
    .recommend-video-box {
            width: 100%;
            margin: 15px 0;

            .recommend-video {
              width: 100%;
              display: flex;
              justify-content: space-between;
              align-items: center;
              margin: 10px 0;
              cursor: pointer;

              .video-pic {
                width: 200px;
                height: 100px;
                background: #000;
                overflow: hidden;
                border-radius: 5px;
                cursor: pointer;
                position: relative;

                img {
                    position: absolute;

                  border-radius: 5px 5px 0 0;
                  transition: all 0.3s;
                  object-fit: cover;

                  &:hover {
                    filter: brightness(90%);
                    transform: scale(1.1);
                    opacity: 1;
                  }
                }
                .duration {
                  color: #eee;
                  font-size: 12px;
                  padding: 0 5px;
                  background: rgba($color: #000, $alpha: 0.8);
                  position: absolute;
                  bottom: 5%;
                  right: 5%;
                }
              }
              .video-info {
                width: 180px;
                margin-left: 10px;
                color: #333;
                font-size: 14px;
                display: inline-block;
                .video-infotitle {
                  padding-bottom: 6px;
                  &:hover {
                    color: #f90;
                  }
                }
                .publish-author-name {
                  color: #939393;
                  font-size: 13px;
                  padding-bottom: 6px;
                  &:hover {
                    color: #f90;
                  }
                }
                .publish-info {
                  color: #939393;
                  font-size: 13px;
                }
              }
            }
          }
    }
</style>
